package com.cupk.entities;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName("users")
public class User {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String username;
    private String password;
    private String email;
    @TableField("full_name")
    private String fullName;
    @TableField("phone_number") // 明确指定列名
    private String phoneNumber; // 新增手机号码字段
    @TableField("department") // 明确指定列名
    private String department; // 新增部门字段
    private String role;
    @TableField("status") // 明确指定列名
    private String status; // 改为String类型以匹配数据库
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    @TableField(exist = false)
    private List<ProjectMember> projectMemberships;
    @TableField("avatar_url") // [新增]
    private String avatarUrl;
    // 便利方法：获取UserStatus枚举
    public UserStatus getUserStatus() {
        if (status == null) return UserStatus.IDLE;
        try {
            return UserStatus.valueOf(status);
        } catch (IllegalArgumentException e) {
            return UserStatus.IDLE;
        }
    }

    // 便利方法：设置UserStatus枚举
    public void setUserStatus(UserStatus userStatus) {
        this.status = userStatus != null ? userStatus.name() : UserStatus.IDLE.name();
    }
}